package com.anjie.powerproject.service.impl;

import com.anjie.powerproject.entity.StationInfo;
import com.anjie.powerproject.service.DayWeatherForecastService;
import com.anjie.powerproject.service.StationInfoService;
import com.anjie.powerproject.strategy.pojo.DayWeather;
import com.anjie.powerproject.strategy.repository.DayWeatherForecastRepository;
import com.anjie.powerproject.strategy.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DayWeatherForecastServiceImpl implements DayWeatherForecastService {

    @Autowired
    StationInfoService stationInfoService;

    @Autowired
    DayWeatherForecastRepository dayWeatherForecastRepository;

    @Override
    public List<DayWeather> getDayWeatherListByCodeAndDateRange(String deviceCode, Date startTime, Date endTime) {
        StationInfo station = stationInfoService.findStationInfoLimitFirst();
        Date limitDate = DateUtils.plusOrMinusDay(endTime, 1).getTime();
        String start = DateUtils.ymdFormat.format(startTime);
        String end = DateUtils.ymdFormat.format(limitDate);

        return dayWeatherForecastRepository.getForecastDayWeatherByDateList(station.getCityCode(), start, end);
    }
}
